package de.clapp.client;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.net.ServerSocket;

import de.clapp.backend.server.CipherServerThread;
import de.clapp.backend.server.ServerThread;
import de.clapp.client.values.Settings;

public class ClientMain
{
    public static void main(String[] args) throws IOException
    {
        // Server Komponenten starten
        // Beliebigen freien Port suchen
        
        ServerSocket s = new ServerSocket(0);
//        ClientSettings.port = Integer.toString(s.getLocalPort());
        ClientSettings.port = "61173";
        s.close();
        
        s = new ServerSocket(0);
        ClientSettings.cipherPort = Integer.toString(s.getLocalPort());
        s.close();

        new ServerThread(Integer.parseInt(ClientSettings.port));
        new CipherServerThread(Integer.parseInt(ClientSettings.cipherPort));
        
        final MainWindow mw = new MainWindow();
        mw.setMinimumSize(Settings.MinSize);

        mw.addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent e)
            {
                // try
                // {
                // Conn.getInstance().con.close();
                // }
                // catch (SQLException e1)
                // {
                // e1.printStackTrace();
                // }
                mw.dispose();
                System.exit(0); // calling the method is a must
            }
        });
    }
}
